package com.spring.demo12.eg6;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

/**
 * @author vhans
 */
@Component
public class UserRegisterService implements ApplicationEventPublisherAware {
    private ApplicationEventPublisher applicationEventPublisher;

    public void registerUser(String name) {
        System.out.printf("当前线程[%s]，用户[%s]注册成功\n", Thread.currentThread(), name);
        this.applicationEventPublisher.publishEvent(new UserRegisterEvent(this, name));
    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }
}
